/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * <p>Project: smvc2022 - Ex2
 * <p>Powered by webrx On 2022-04-01 15:10:56
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex2 {
    public static void main(String[] args) {
        File dst = new File("C:\\Users\\WANG\\IdeaProjects\\smvc2022");
        search(dst);
    }

    /**
     * Description: 递归调用方法
     *
     * @date: 2022/4/1 15:20
     * @params: [java.io.File]
     * @return: void
     */
    public static void search(File src) {
        Pattern p = Pattern.compile("1[3,5,8]\\d{9}");
        if (src.isDirectory()) {
            for (File file : src.listFiles()) {
                if (file.isDirectory()) {
                    search(file);
                } else if (file.isFile() && file.getName().toLowerCase().endsWith(".java")) {
                    try (BufferedReader buf = new BufferedReader(new FileReader(file))) {
                        String text = buf.lines().collect(Collectors.joining());
                        Matcher m = p.matcher(text);
                        while (m.find()) {
                            System.out.printf("手机号：%s，所有文件：%s位置。%n", m.group(), file.getAbsolutePath());
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }
    }
}
